package com.funmi.lizip.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import com.funmi.lizip.common.base.R;
import com.funmi.lizip.entity.EcMonitoring;
import com.funmi.lizip.entity.Resource;
import com.funmi.lizip.entity.dto.EcMonitoring.EcMonitoringAddRequest;
import com.funmi.lizip.entity.dto.EcMonitoring.EcMonitoringQueryRequest;
import com.funmi.lizip.entity.dto.EcMonitoring.EcMonitoringUpdateRequest;
import com.funmi.lizip.entity.vo.EcMonitoringVo;
import com.funmi.lizip.service.EcMonitoringService;
import com.funmi.lizip.service.ResourceService;
import com.funmi.lizip.utils.MyJsonUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 */
@Api(tags = "资源现状模块")
@RestController
@RequestMapping("/resource")
@Slf4j
public class ResourceController {

    @Autowired
    private ResourceService resourceService;

    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "获取 资源现状")
    @GetMapping("")
    public R get(){
        return R.success().data(resourceService.getById(1));
    }

    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "修改 生态监测体系运行内容")
    @PutMapping("")
    public R update(@RequestBody HashMap<String, String> contents) {
        Resource resource = resourceService.getById(1);
        resource.setContent(contents.get("content"));
        boolean b = resourceService.updateById(resource);
        if (b) {
            return R.success().message("修改成功");
        }
        return R.fail().message("修改失败");
    }

}
